home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Tennis / Paddle.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-30  |  3.0 KB  |  101 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    Paddle.h
  7. //----------------------------------------------------------------------------------------------
  8.  
  9.  
  10. #ifndef __PADDLE_H
  11. #define __PADDLE_H
  12.  
  13. //----------------------------------------------------------------------------------------------
  14. // Include files
  15. //----------------------------------------------------------------------------------------------
  16.  
  17. #include "directdraw.h"
  18. #include "observer.h"
  19. #include "ball.h"
  20.  
  21. //----------------------------------------------------------------------------------------------
  22. // Defined constants
  23. //----------------------------------------------------------------------------------------------
  24.  
  25. #define MAX_ROTATION  50
  26. #define PADDLE_SIZE      30
  27. #define PADDLE_WIDTH  10
  28. #define STEP_SIZE      1.9f
  29. #define HIT_FORCE      5
  30. #define PADDLE_HEIGHT 30
  31. #define PADDLE_UP      -1
  32. #define PADDLE_DOWN   1
  33. #define ROTATE_SPEED  2
  34.  
  35. //----------------------------------------------------------------------------------------------
  36. // CPaddle: Represents a paddle (which can be controlled by a player to return the ball)
  37. //----------------------------------------------------------------------------------------------
  38.  
  39. class CPaddle : public CSubject {
  40.  
  41. public:
  42.                     CPaddle() {
  43.                         region = NULL;
  44.                         instantiations++;
  45.                         id = instantiations;                        
  46.                     }
  47.  
  48.                     ~CPaddle() {
  49.                         if (region != NULL) {
  50.                             DeleteObject(region);
  51.                         }
  52.                     }
  53.  
  54. public:
  55.     virtual void    ResetForService(BOOL HasService);
  56.     void            SetPosition(int x, int y, int angle = 0) { px = (float)x; py = (float)y; rotation = 0; Rotate(angle); }
  57.     void            SetPlayField(LPRECT lpRect) { field = *lpRect; }
  58.     void            SetColor(COLORREF ref) { color = ref; }
  59.     void            SetDirection(int dir) { direction = dir; } 
  60.     BOOL            PtInPaddle(int x, int y);
  61.     BOOL            RectInPaddle(const RECT * lpRect);
  62.     void            BallCollision(CTennisBall * ball);
  63.     LPRECT            GetField() { return &field; }
  64.     int                GetId() { return id; }
  65.     int                GetDirection() { return direction; }
  66.     int                GetColor() { return color; }
  67.  
  68.     void            Left(); 
  69.     void            Right(); 
  70.     void            Up(); 
  71.     void            Down(); 
  72.     
  73.     virtual void    Paint(LPDDS lpdds);
  74.     void            Rotate(int angle);
  75.  
  76.     virtual void    Update() { /* skip */ }
  77.  
  78. public:
  79.     int                bounce; // used by TennisField - do not use in CPaddle or derived classes
  80.     int                score;  // used by TennisField - do not use in CPaddle or derived classes
  81.  
  82. protected:
  83.     void            RecalculatePaddle();
  84.     virtual void    OnBallCollision() { /* empty default implementation */ }
  85.  
  86. protected:
  87.     static int        instantiations;
  88.     int                id;
  89.     POINT            paddle[4];
  90.     HRGN            region;
  91.     COLORREF        color;
  92.     RECT            field;
  93.     float            px, py;
  94.     int                rotation;
  95.     float            nx, ny;
  96.     int                direction;
  97. };
  98.  
  99. //----------------------------------------------------------------------------------------------
  100. #endif // __PADDLE_H
  101.